﻿namespace FiftyOne.Foundation.Mobile.Detection.Wurfl.Handlers
{
    using FiftyOne.Foundation.Mobile.Detection.Wurfl;
    using System;

    internal class SafariDesktopHandler : RegexSegmentHandler
    {
        private const string DEFAULT_DEVICE = "safari";
        private const byte EXTRA_CONFIDENCE = 1;
        private static readonly string[] PATTERNS = new string[] { @"(?<=Mozilla/\d.\d \()[^;]+", @"(?<=Safari/)[\d.]+" };
        private static readonly string[] SUPPORTED_ROOT_DEVICES = new string[] { "safari" };

        internal SafariDesktopHandler() : base(PATTERNS, new int[] { 3, 1 })
        {
            base._firstMatchOnly = true;
        }

        protected internal override bool CanHandle(string userAgent)
        {
            return ((userAgent.StartsWith("Mozilla") && userAgent.Contains("Safari")) && ((userAgent.Contains("Windows") || userAgent.Contains("Macintosh")) || userAgent.Contains("X11")));
        }

        internal override byte Confidence
        {
            get
            {
                return (byte) (base.Confidence + 1);
            }
        }

        internal override DeviceInfo DefaultDevice
        {
            get
            {
                DeviceInfo deviceInfoFromID = Provider.Instance.GetDeviceInfoFromID("safari");
                if (deviceInfoFromID != null)
                {
                    return deviceInfoFromID;
                }
                return base.DefaultDevice;
            }
        }

        protected override string[] SupportedRootDeviceIds
        {
            get
            {
                return SUPPORTED_ROOT_DEVICES;
            }
        }
    }
}

